home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume21 / rayshade / part01 next >
Encoding:
Internet Message Format  |  1990-03-21  |  59.9 KB

  1. Subject:  v21i008:  A ray tracing program, Part01/08
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Craig Kolb <craig@weedeater.math.yale.edu>
  7. Posting-number: Volume 21, Issue 8
  8. Archive-name: rayshade/part01
  9.  
  10. This is version 3.0 of rayshade, a raytracing program.  Rayshade reads
  11. a multi-line ASCII file describing a scene to be rendered and produces
  12. a Utah Raster RLE format file of the raytraced image.
  13.  
  14. Rayshade features:
  15.  
  16.     Eight types of primitives (box, cone, cylinder, height field,
  17.     polygon, sphere, superquadric, flat- and Phong-shaded triangle)
  18.  
  19.     Composite objects
  20.  
  21.     Point, directional, and extended (area) light sources
  22.  
  23.     Solid procedural texturing and bump mapping of primitives, objects,
  24.         and individual instances of objects
  25.  
  26.     Antialiasing through adaptive supersampling or "jittered" sampling
  27.  
  28.     Arbitrary linear transformations on primitives,
  29.         instances of objects, and texture/bump maps
  30.  
  31.     Use of uniform spatial subdivision or hierarchy of bounding
  32.         volumes to speed rendering
  33.  
  34.     Options to facilitate rendering of stereo pairs
  35.  
  36.     Support for the C-Linda parallel programming language
  37.  
  38. Rayshade has been tested on many different UNIX-based computers.  If your
  39. machine has a C compiler and enough memory (at least 2Mb), rayshade should
  40. be fairly easy to port.  Be warned that rayshade uses yacc and lex to
  41. process input files.  If you do not have lex and yacc, try to get flex and
  42. bison from the Free Software Foundation folks (ftp to prep.ai.mit.edu).
  43.  
  44.  
  45. Thanks,
  46. Craig
  47. kolb@yale.edu
  48.  
  49. #! /bin/sh
  50. # This is a shell archive.  Remove anything before this line, then unpack
  51. # it by saving it into a file and typing "sh file".  To overwrite existing
  52. # files, type "sh file -c".  You can also feed this as standard input via
  53. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  54. # will see the following message at the end:
  55. #        "End of archive 1 (of 8)."
  56. # Contents:  Changes Copyright Examples Examples/balls.ray
  57. #   Examples/planet.map Examples/planet.ray Examples/solids.ray
  58. #   MANIFEST README References TODO doc src src/atmosphere.c src/box.c
  59. #   src/constants.h src/defaults.h src/input_lex.l src/memory.c
  60. #   src/patchlevel.h src/plane.c src/raymath.c src/raytrace.h
  61. #   src/texture.h src/typedefs.h src/version.c src/viewing.c
  62. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  63. if test -f 'Changes' -a "${1}" != "-c" ; then 
  64.   echo shar: Will not clobber existing file \"'Changes'\"
  65. else
  66. echo shar: Extracting \"'Changes'\" \(1251 characters\)
  67. sed "s/^X//" >'Changes' <<'END_OF_FILE'
  68. XBugfixes
  69. X--------
  70. X
  71. XWas possible to divide by zero in main.c and intersect.c.
  72. XSuperquadric normals were sometimes unnecessarily flipped.
  73. XFog and mist should be applied after shading calculations.
  74. XReading colormap file with > 256 entries dumped core.
  75. XCouldn't comment out slashes.
  76. XRemoved check of dotp(ray, norm) in shade().
  77. XAdded check for s < lightdist in inshadow().
  78. XVarious problems in grid.c.
  79. X
  80. XPortability Changes
  81. X-------------------
  82. X
  83. XCalculation of index in poly.c and triangle.c was non-portable.
  84. XSome code in intersect.c was apparently non-portable.
  85. XModified functions to no longer return structures.
  86. X
  87. XMisc. Changes
  88. X-------------
  89. X
  90. XNo longer need use "endfile" keyword at the end of input files.
  91. XAdded adaptive ray tree pruning and -T option.
  92. XCombined -R, -G and -B options into -C option.
  93. XAdded -R option.
  94. XOptimization of IntBounds().
  95. XMerged int_grid() and DDA().
  96. XAdded "samples", "jittered", "cutoff", "contrast" and "adaptive" keywords.
  97. XFlat-shaded triangles now require less storage space.
  98. XShadow caching is now the default.
  99. XThe number of shadow cache hits are reported.
  100. XShadow cache hits are counted as "shadow rays".
  101. XShadow hits are counted as "intersecting rays".
  102. XThe number of shadow hits is reported.
  103. XVarious cleanups courtesy of lint.
  104. END_OF_FILE
  105. if test 1251 -ne `wc -c <'Changes'`; then
  106.     echo shar: \"'Changes'\" unpacked with wrong size!
  107. fi
  108. # end of 'Changes'
  109. fi
  110. if test -f 'Copyright' -a "${1}" != "-c" ; then 
  111.   echo shar: Will not clobber existing file \"'Copyright'\"
  112. else
  113. echo shar: Extracting \"'Copyright'\" \(806 characters\)
  114. sed "s/^X//" >'Copyright' <<'END_OF_FILE'
  115. X/*
  116. X * Copyright (C) 1989, Craig E. Kolb
  117. X *
  118. X * This software may be freely copied, modified, and redistributed,
  119. X * provided that this copyright notice is preserved on all copies.
  120. X * 
  121. X * There is no warranty or other guarantee of fitness for this software,
  122. X * it is provided solely "as is".  Bug reports or fixes may be sent
  123. X * to the author, who may or may not act on them as he desires.
  124. X *
  125. X * You may not include this software in a program or other software product
  126. X * without supplying the source, or without informing the end-user that the 
  127. X * source is available for no extra charge.
  128. X *
  129. X * If you modify this software, you should include a notice giving the
  130. X * name of the person performing the modification, the date of modification,
  131. X * and the reason for such modification.
  132. X *
  133. X * $Id$
  134. X *
  135. X * $Log$
  136. X */
  137. END_OF_FILE
  138. if test 806 -ne `wc -c <'Copyright'`; then
  139.     echo shar: \"'Copyright'\" unpacked with wrong size!
  140. fi
  141. # end of 'Copyright'
  142. fi
  143. if test ! -d 'Examples' ; then
  144.     echo shar: Creating directory \"'Examples'\"
  145.     mkdir 'Examples'
  146. fi
  147. if test -f 'Examples/balls.ray' -a "${1}" != "-c" ; then 
  148.   echo shar: Will not clobber existing file \"'Examples/balls.ray'\"
  149. else
  150. echo shar: Extracting \"'Examples/balls.ray'\" \(915 characters\)
  151. sed "s/^X//" >'Examples/balls.ray' <<'END_OF_FILE'
  152. X/*
  153. X * This file is the result of feeding "balls" from Eric Haines'
  154. X * SPD through nff2shade.awk and then hand-tweaking things.
  155. X */
  156. Xmaxdepth 3
  157. Xeyep 2.1 1.3 1.7
  158. Xlookp 0 0 0
  159. Xup 0 0 1
  160. Xfov 45
  161. Xscreen 256 256
  162. Xbackground 0.078 0.361 0.753
  163. Xsurface s1  0.15 0.1 0.045  1. 0.75 0.33  0. 0. 0.  0. 0. 0. 0.
  164. Xplane s1 0 0 1 0 0 -.5
  165. Xsurface s2  0.035 0.0325 0.025  0.5 0.45 0.35  0.8 0.8 0.8  3. 0.5 0. 0.
  166. Xsphere s2 0.5 0 0 0 texture bump 0.3 scale 0.04 0.04 0.04
  167. Xsphere s2 0.166667 0.272166 0.272166 0.544331
  168. Xsphere s2 0.166667 0.643951 0.172546 0
  169. Xsphere s2 0.166667 0.172546 0.643951 0
  170. Xsphere s2 0.166667 -0.371785 0.0996195 0.544331
  171. Xsphere s2 0.166667 -0.471405 0.471405 0
  172. Xsphere s2 0.166667 -0.643951 -0.172546 0
  173. Xsphere s2 0.166667 0.0996195 -0.371785 0.544331
  174. Xsphere s2 0.166667 -0.172546 -0.643951 0
  175. Xsphere s2 0.166667 0.471405 -0.471405 0 
  176. Xlight 0.288675 point 4 3 2
  177. Xlight 0.288675 point 1 -4 4
  178. Xlight 0.288675 point -3 1 5
  179. END_OF_FILE
  180. if test 915 -ne `wc -c <'Examples/balls.ray'`; then
  181.     echo shar: \"'Examples/balls.ray'\" unpacked with wrong size!
  182. fi
  183. # end of 'Examples/balls.ray'
  184. fi
  185. if test -f 'Examples/planet.map' -a "${1}" != "-c" ; then 
  186.   echo shar: Will not clobber existing file \"'Examples/planet.map'\"
  187. else
  188. echo shar: Extracting \"'Examples/planet.map'\" \(2551 characters\)
  189. sed "s/^X//" >'Examples/planet.map' <<'END_OF_FILE'
  190. X40 128 200
  191. X40 128 200
  192. X41 129 201
  193. X42 130 202
  194. X43 131 202
  195. X44 132 203
  196. X45 133 204
  197. X46 134 204
  198. X47 135 205
  199. X48 136 206
  200. X48 136 206
  201. X49 137 207
  202. X50 138 208
  203. X51 139 209
  204. X52 140 209
  205. X53 141 210
  206. X54 142 211
  207. X55 143 211
  208. X56 144 212
  209. X57 145 213
  210. X57 145 213
  211. X58 146 214
  212. X59 147 215
  213. X60 148 216
  214. X61 149 216
  215. X62 150 217
  216. X63 151 218
  217. X64 152 218
  218. X65 153 219
  219. X66 154 220
  220. X66 154 220
  221. X67 155 221
  222. X68 156 222
  223. X69 157 222
  224. X70 158 223
  225. X71 159 224
  226. X72 160 225
  227. X73 161 225
  228. X74 162 226
  229. X75 163 227
  230. X75 163 227
  231. X76 164 228
  232. X77 165 229
  233. X78 166 229
  234. X79 167 230
  235. X80 168 231
  236. X81 169 232
  237. X82 170 232
  238. X83 171 233
  239. X84 172 234
  240. X84 172 234
  241. X85 173 235
  242. X86 174 236
  243. X87 175 236
  244. X88 176 237
  245. X89 177 238
  246. X90 178 238
  247. X91 179 239
  248. X92 180 240
  249. X93 181 241
  250. X93 181 241
  251. X94 182 242
  252. X95 183 243
  253. X96 184 243
  254. X97 185 244
  255. X98 186 245
  256. X99 187 245
  257. X100 188 246
  258. X101 189 247
  259. X102 190 248
  260. X102 190 248
  261. X103 191 249
  262. X104 192 250
  263. X105 193 250
  264. X106 194 251
  265. X107 195 252
  266. X108 196 252
  267. X109 197 253
  268. X110 198 254
  269. X111 199 255
  270. X244 211 1
  271. X240 211 1
  272. X237 211 1
  273. X234 211 1
  274. X231 211 1
  275. X228 211 1
  276. X224 211 1
  277. X221 211 1
  278. X218 211 1
  279. X215 211 1
  280. X212 211 1
  281. X209 211 1
  282. X205 211 1
  283. X202 211 1
  284. X199 211 1
  285. X196 211 1
  286. X193 211 1
  287. X190 211 1
  288. X186 211 1
  289. X183 211 1
  290. X180 211 1
  291. X177 211 1
  292. X174 211 1
  293. X171 211 1
  294. X132 208 1
  295. X129 206 1
  296. X125 204 1
  297. X122 201 1
  298. X119 199 1
  299. X115 197 1
  300. X112 194 1
  301. X108 192 1
  302. X105 190 1
  303. X102 187 1
  304. X98 185 1
  305. X95 183 1
  306. X91 180 1
  307. X88 178 1
  308. X84 176 1
  309. X81 173 1
  310. X78 171 1
  311. X74 169 1
  312. X71 166 1
  313. X67 164 1
  314. X64 162 1
  315. X61 159 1
  316. X57 157 1
  317. X54 155 1
  318. X50 152 1
  319. X47 150 1
  320. X44 148 1
  321. X40 145 1
  322. X37 143 1
  323. X33 141 1
  324. X30 138 1
  325. X27 136 1
  326. X23 134 1
  327. X20 131 1
  328. X16 129 1
  329. X13 127 1
  330. X10 124 1
  331. X6 122 1
  332. X3 120 1
  333. X0 118 1
  334. X3 116 1
  335. X6 115 1
  336. X9 113 1
  337. X12 112 1
  338. X15 110 1
  339. X18 109 1
  340. X21 107 1
  341. X25 106 1
  342. X28 104 1
  343. X31 103 1
  344. X34 101 1
  345. X37 100 1
  346. X40 98 1
  347. X43 97 1
  348. X46 96 1
  349. X50 94 1
  350. X53 93 1
  351. X56 91 1
  352. X59 90 1
  353. X62 88 1
  354. X65 87 1
  355. X68 85 1
  356. X71 84 1
  357. X75 82 1
  358. X78 81 1
  359. X81 79 1
  360. X84 78 1
  361. X87 77 1
  362. X90 75 1
  363. X93 74 1
  364. X96 72 1
  365. X100 71 1
  366. X103 69 1
  367. X106 68 1
  368. X109 66 1
  369. X112 65 1
  370. X115 63 1
  371. X118 62 1
  372. X122 61 1
  373. X121 61 1
  374. X120 61 1
  375. X118 60 1
  376. X117 60 1
  377. X115 59 1
  378. X114 59 1
  379. X113 59 1
  380. X111 58 1
  381. X110 58 1
  382. X109 58 1
  383. X111 59 1
  384. X114 60 1
  385. X116 62 1
  386. X119 63 1
  387. X121 65 1
  388. X124 66 1
  389. X126 68 1
  390. X129 69 1
  391. X131 71 1
  392. X134 72 1
  393. X136 74 1
  394. X139 75 1
  395. X141 77 1
  396. X144 78 1
  397. X147 80 1
  398. X149 81 1
  399. X152 83 1
  400. X154 84 1
  401. X157 86 1
  402. X159 87 1
  403. X162 89 1
  404. X164 90 1
  405. X167 92 1
  406. X169 93 1
  407. X172 95 1
  408. X174 96 1
  409. X177 98 1
  410. X180 99 1
  411. X182 101 1
  412. X185 102 1
  413. X187 104 1
  414. X190 105 1
  415. X192 107 1
  416. X195 108 1
  417. X197 110 1
  418. X200 111 1
  419. X202 113 1
  420. X205 114 1
  421. X207 116 1
  422. X210 117 1
  423. X213 119 2
  424. X210 120 9
  425. X208 122 16
  426. X205 124 23
  427. X203 126 30
  428. X200 128 37
  429. X198 129 44
  430. X195 131 51
  431. X193 133 59
  432. X190 135 66
  433. X188 137 73
  434. X186 138 80
  435. X183 140 87
  436. X181 142 94
  437. X178 144 101
  438. X176 146 109
  439. X173 148 116
  440. X254 255 255
  441. X254 255 254
  442. X254 255 254
  443. X254 255 253
  444. X254 255 253
  445. X254 255 253
  446. END_OF_FILE
  447. if test 2551 -ne `wc -c <'Examples/planet.map'`; then
  448.     echo shar: \"'Examples/planet.map'\" unpacked with wrong size!
  449. fi
  450. # end of 'Examples/planet.map'
  451. fi
  452. if test -f 'Examples/planet.ray' -a "${1}" != "-c" ; then 
  453.   echo shar: Will not clobber existing file \"'Examples/planet.ray'\"
  454. else
  455. echo shar: Extracting \"'Examples/planet.ray'\" \(427 characters\)
  456. sed "s/^X//" >'Examples/planet.ray' <<'END_OF_FILE'
  457. X/*
  458. X * Example rayshade input file describing a single texture-mapped sphere.
  459. X *
  460. X * C. Kolb 9/89
  461. X */
  462. Xscreen 256 256
  463. Xlight 1.0 0.9 0.8 directional 1. -1. 1.
  464. Xeyep 0. -4. 0.
  465. Xsurface basesurf .16 .15 .14 .8 .75 .7 0 0 0 0 0 0 0
  466. Xsphere basesurf 1.0 0 0 0
  467. X    texture fbm     0.        /* offset */
  468. X            1.        /* scale */
  469. X            0.3        /* h */
  470. X            2.0        /* lambda */
  471. X            6        /* octaves */
  472. X            -.2        /* thresh */
  473. X            planet.map     /* mapname */
  474. X        scale 0.7 0.7 0.7 
  475. END_OF_FILE
  476. if test 427 -ne `wc -c <'Examples/planet.ray'`; then
  477.     echo shar: \"'Examples/planet.ray'\" unpacked with wrong size!
  478. fi
  479. # end of 'Examples/planet.ray'
  480. fi
  481. if test -f 'Examples/solids.ray' -a "${1}" != "-c" ; then 
  482.   echo shar: Will not clobber existing file \"'Examples/solids.ray'\"
  483. else
  484. echo shar: Extracting \"'Examples/solids.ray'\" \(856 characters\)
  485. sed "s/^X//" >'Examples/solids.ray' <<'END_OF_FILE'
  486. X/*
  487. X * solids.ray
  488. X *
  489. X * Example rayshade input file.
  490. X *
  491. X * Render using:
  492. X *    rayshade solids.ray > solids.rle
  493. X *
  494. X * For previewing purposes, you may wish to use the -P option.
  495. X * Craig Kolb 9/89
  496. X */
  497. Xeyep 0. 25. 7.
  498. Xscreen 128 128
  499. Xjittered
  500. Xlight 1.4 extended -15. 20. 15. 1.4
  501. Xsurface red .02 0 0 .5 0 0 .2 .2 .2 32. 0.5 0 0
  502. Xsurface blacktile 0.01 0.015 0.01 0.02 0.03 0.02 0.3 0.35 0.3 30 0.33 0 0
  503. Xsurface white .02 .02 .008 .5 .5 .25 0.8 0.8 0.8 18 0.2 0 0
  504. Xsurface glass 0.02 0.02 0.02  0. 0. 0.  0.8 0.8 0.8  25 0.2 .3 1.15
  505. X
  506. Xsphere red 4. 3 0 0
  507. X/*
  508. X * Cone actually sticks through ground plane.  This solves problems
  509. X * that arise when the bottom of the cone and the plane are coincident.
  510. X */
  511. Xcone glass -5. 3 -4.1 -5. 3. 4. 4. 0.
  512. X
  513. Xplane white 0. 0. 1. 0. 0. -4. 
  514. X        texture marble scale 4. 4. 4.
  515. X        texture checker blacktile translate 0. 0. 0.3 scale 4. 4. 4.
  516. END_OF_FILE
  517. if test 856 -ne `wc -c <'Examples/solids.ray'`; then
  518.     echo shar: \"'Examples/solids.ray'\" unpacked with wrong size!
  519. fi
  520. # end of 'Examples/solids.ray'
  521. fi
  522. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  523.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  524. else
  525. echo shar: Extracting \"'MANIFEST'\" \(3432 characters\)
  526. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  527. X   File Name        Archive #    Description
  528. X-----------------------------------------------------------
  529. X BLURB.UTAH                 3    Blurb from Utah Raster Toolkit
  530. X Changes                    1    List of recent changes
  531. X Copyright                  1    Copyright information    
  532. X Examples                   1    Example input files    
  533. X Examples/balls.ray         1    Tweaked output from Eric Haines' SPD
  534. X Examples/planet.map        1    Colormap for planet image
  535. X Examples/planet.ray        1    Simple planet example
  536. X Examples/pool.ray          2    Pool table example
  537. X Examples/solids.ray        1    Transparency/reflectivity example
  538. X MANIFEST                   1    This shipping list
  539. X README                     1    General information
  540. X References                 1    Publications of interest
  541. X TODO                       1    List of suggested extensions    
  542. X doc                        1    Documentation directory
  543. X doc/primitive.ms           7    Tutorial on adding primitives
  544. X doc/rayshade.1             8    Rayshade man page
  545. X doc/texture.ms             5    Tutorial on adding textures
  546. X nff2shade.awk              2    Awk script to convert NFF-->rayshade
  547. X src                        1    Source directory
  548. X src/Makefile               4    Make control file
  549. X src/atmosphere.c           1    Atmospheric effects
  550. X src/bounds.c               3    Bounding box routines
  551. X src/box.c                  1    Box primitive
  552. X src/cone.c                 3    Cone primitive
  553. X src/constants.h            1    Various constants
  554. X src/cylinder.c             3    Cylinder primitive
  555. X src/datatypes.h            2    Datatype definitions
  556. X src/defaults.h             1    Default values
  557. X src/funcdefs.h             2    Function declarations
  558. X src/grid.c                 5    Ray/grid intersection
  559. X src/hf.c                   6    Heightfield primitive
  560. X src/input.c                2    Routines to handle #include
  561. X src/input_lex.l            1    Lexical analysis
  562. X src/input_yacc.y           6    Parsing    
  563. X src/intersect.c            3    Top-level intersection routines
  564. X src/light.c                3    Shadow generation
  565. X src/list.c                 2    Ray/list intersection
  566. X src/main.c                 2    Driving routine
  567. X src/malloc.c               4    A fast storage allocator
  568. X src/matrix.c               5    Matrix manipulation
  569. X src/memory.c               1    Memory management
  570. X src/noise.c                4    Perlin-style Noise and DNoise()
  571. X src/object.c               3    Misc. object functions
  572. X src/outputp.c              2    Image file interface
  573. X src/patchlevel.h           1    Patchlevel information
  574. X src/plane.c                1    Plane primitive
  575. X src/poly.c                 4    Polygon primitive
  576. X src/primobj.h              2    Primitive object definitions
  577. X src/ray_options.c          3    Command line parsing
  578. X src/raymath.c              1    Vector functions
  579. X src/raytrace.c             6    Sampling/antialiasing
  580. X src/raytrace.h             1    Sampling patters
  581. X src/setup.c                2    Initialization
  582. X src/shade.c                5    Lighting calculations
  583. X src/sphere.c               2    Sphere primitive
  584. X src/superq.c               2    Superquadric primitive
  585. X src/surface.c              2    Surface & color functions
  586. X src/texture.c              4    Texturing & bump mapping
  587. X src/texture.h              1    Texture definitions
  588. X src/triangle.c             4    Triangle primitive
  589. X src/typedefs.h             1    Misc. typedefs
  590. X src/version.c              1    Version information
  591. X src/viewing.c              1    Viewing transformations
  592. X src/voxels.c               3    Voxel allocation & initialization
  593. END_OF_FILE
  594. if test 3432 -ne `wc -c <'MANIFEST'`; then
  595.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  596. fi
  597. # end of 'MANIFEST'
  598. fi
  599. if test -f 'README' -a "${1}" != "-c" ; then 
  600.   echo shar: Will not clobber existing file \"'README'\"
  601. else
  602. echo shar: Extracting \"'README'\" \(5201 characters\)
  603. sed "s/^X//" >'README' <<'END_OF_FILE'
  604. XThis is version 3.0 of rayshade, a raytracing program.  Rayshade reads
  605. Xa multi-line ASCII file describing a scene to be rendered and produces
  606. Xa Utah Raster RLE format file of the raytraced image.
  607. X
  608. XRayshade features:
  609. X
  610. X    Eight types of primitives (box, cone, cylinder, height field,
  611. X    polygon, sphere, superquadric, flat- and Phong-shaded triangle)
  612. X
  613. X    Composite objects
  614. X
  615. X    Point, directional, and extended (area) light sources
  616. X
  617. X    Solid procedural texturing and bump mapping of primitives, objects,
  618. X        and individual instances of objects
  619. X
  620. X    Antialiasing through adaptive supersampling or "jittered" sampling
  621. X
  622. X    Arbitrary linear transformations on primitives,
  623. X        instances of objects, and texture/bump maps
  624. X
  625. X    Use of uniform spatial subdivision or hierarchy of bounding
  626. X        volumes to speed rendering
  627. X
  628. X    Options to facilitate rendering of stereo pairs
  629. X
  630. X    Support for the C-Linda parallel programming language
  631. X
  632. X
  633. XThis version supersedes all previous versions, and it is to this release
  634. Xthat subsequent patches should be applied.
  635. X
  636. XRayshade has been tested on many different UNIX-based computers.  If your
  637. Xmachine has a C compiler and enough memory (at least 2Mb), rayshade should
  638. Xbe fairly easy to port.  Be warned that rayshade uses yacc and lex to
  639. Xprocess input files.  If you do not have lex and yacc, try to get flex and
  640. Xbison from the Free Software Foundation folks (ftp to prep.ai.mit.edu).
  641. X
  642. XNormally, rayshade makes use of the Utah Raster toolkit.  I strongly
  643. Xsuggest you get a copy of the toolkit, as it provides a host of useful tools
  644. Xfor image manipulation and a library for reading/reading the toolkit's
  645. X"RLE" format image files.  UTAH.BLURB is the "blurb" file from the latest
  646. Xdistribution of the toolkit, which can be obtained via anonymous ftp from
  647. Xcs.utah.edu (128.110.4.21), weedeater.math.yale.edu (192.26.88.42),
  648. Xnl.cs.cmu.edu (128.22.222.56), and uunet.uu.net.  Also of interest is the
  649. X"fbm" library, available from nl.cs.cmu.edu:/usr/mlm/ftp/fbm.tar.Z, which
  650. Xprovides tools for converting Utah Raster RLE format images to/from other
  651. Xformats.
  652. X
  653. XIf you do not want to or cannot use the Utah Raster toolkit, compile-time
  654. Xswitches are provided to create image files using a generic format very
  655. Xsimilar to that used by Mark VandeWettering's raytracer.  See the Makefile
  656. Xand src/outputp.c for details.
  657. X
  658. XThe directory "src" contains the source to rayshade.  To compile, edit the
  659. XMakefile in that directory and change include file and library paths and set
  660. XCFLAGS and LIBS to whatever is appropriate for your particular hardware/
  661. Xsoftware configuration.
  662. X
  663. XThe file doc/rayshade.1 contains a brief manual page which covers most things
  664. Xa casual user will need to know in order to produce raytraced images.
  665. XA tutorial on adding new textures on rayshade is included in doc/texture.ms.
  666. XA similar document on adding new primitives to rayshade is in
  667. Xdoc/primitive.ms.  Unfortunately, there is as yet no technical documentation.
  668. X
  669. XOnce you've compiled rayshade, you can test it using the example input
  670. Xfiles in the Examples directory.  You can also run the output of
  671. XEric Haines' Standard Procedural Database through awk using the
  672. X"nff2shade.awk" script, and feed the results to rayshade.  Note that for
  673. Xseveral of the databases, you will need to tweak the data a bit to achieve
  674. Xoptimal runtimes.  See nff2shade.awk for details.
  675. X
  676. XRayshade was not designed to be, nor is it, the be-all and end-all of
  677. Xraytracers.  It was meant to be reasonably fast, portable, and easy to 
  678. Xmodify.  It has some nice features which allow you to produce
  679. Xpretty pictures, but there are countless extensions, modifications,
  680. Xand improvements which could be made.  There are many routines which may be
  681. Xoptimized and many features which could be added.  For a list of suggested
  682. Ximprovements and projects see "TODO".  You are encouraged to modify the
  683. Xsource code left and right.
  684. X
  685. XRayshade had its start as an "introductory" public domain raytracer written
  686. Xby Roman Kuchkuda.  During 1987-88 the first version of rayshade was written
  687. Xby Craig Kolb, David P. Dobkin (the original cylinder, cone and extinct torus-
  688. Xtracing code), and David C. Hoffman (the original octree code).  Craig Kolb
  689. Xwrote the current version of rayshade during the fall of 1988 and has made a
  690. Xlarge number of changes since then.
  691. X
  692. XThe current version of rayshade owes much to a number of people who have
  693. Xmade suggestions, fixed bugs, and who have been all-around good sports about
  694. Xthe whole thing.  Thanks to David Dobkin, Eric Haines, Lefteris Koutsofios,
  695. XKen Musgrave, Przemek Prusinkiewicz, and Allan Snider for their encouragement,
  696. Xcomments, and willingness to be on the Front Lines.  Thanks also to Roman
  697. XKuchkuda for providing a base upon which to build.  Special thanks to Robert
  698. XSkinner for providing the Noise(), DNoise(), and other texturing functions
  699. Xand allowing them to be redistributed.
  700. X
  701. XIf you find any bugs, make any useful extensions, have a nice input
  702. Xfile, port rayshade to a new environment, or need assistance understanding a
  703. Xparticularly braindamaged section of code, please let me know.  I can be most
  704. Xeasily reached by email.
  705. X
  706. XCraig Kolb 10/27/89
  707. Xkolb@yale.edu
  708. X
  709. XYale University Dept. of Mathematics
  710. XP.O. Box 2155 Yale Station
  711. XNew Haven, CT  06520-2155
  712. END_OF_FILE
  713. if test 5201 -ne `wc -c <'README'`; then
  714.     echo shar: \"'README'\" unpacked with wrong size!
  715. fi
  716. # end of 'README'
  717. fi
  718. if test -f 'References' -a "${1}" != "-c" ; then 
  719.   echo shar: Will not clobber existing file \"'References'\"
  720. else
  721. echo shar: Extracting \"'References'\" \(2965 characters\)
  722. sed "s/^X//" >'References' <<'END_OF_FILE'
  723. X#
  724. X# Publications of particular interest to rayshade-hackers.
  725. X#
  726. X# Mostly snipped from the Ray Tracing Bibliography assembled by
  727. X# Paul Heckbert and Eric Haines.
  728. X#
  729. X%A Robert L. Cook
  730. X%A Thomas Porter
  731. X%A Loren Carpenter
  732. X%T Distributed Ray Tracing
  733. X%J Computer Graphics
  734. X(SIGGRAPH '84 Proceedings)
  735. X%V 18
  736. X%N 3
  737. X%D July 1984
  738. X%P 137-145
  739. X%Z Monte Carlo distribution of rays to get
  740. Xgloss, translucency, penumbras, depth of field, motion blur
  741. X%K probabilistic ray tracing, monte carlo, motion blur, stochastic sampling
  742. X
  743. X%A Robert L. Cook
  744. X%T Stochastic Sampling in Computer Graphics
  745. X%J ACM Transactions on Graphics
  746. X%V 5
  747. X%N 1
  748. X%D Jan. 1986
  749. X%P 51-72
  750. X
  751. X%A Akira Fujimoto
  752. X%A Takayuki Tanaka
  753. X%A Kansei Iwata
  754. X%T ARTS: Accelerated Ray-Tracing System
  755. X%J IEEE Computer Graphics and Applications
  756. X%D Apr. 1986
  757. X%P 16-26
  758. X%K octree
  759. X
  760. X%A Andrew S. Glassner
  761. X%A Jim Arvo
  762. X%A Robert L. Cook
  763. X%A Eric Haines
  764. X%A Pat Hanrahan
  765. X%A Paul Heckbert
  766. X%A David B. Kirk
  767. X%B An Introduction to Ray Tracing
  768. X%I Academic Press
  769. X%C London
  770. X%D 1989
  771. X
  772. X%A Eric Haines
  773. X%T A Proposal for Standard Graphics Environments
  774. X%J IEEE Computer Graphics and Applications
  775. X%V 7
  776. X%N 11
  777. X%D Nov. 1987
  778. X%P 3-5
  779. X%K benchmark
  780. X%Z renderer benchmarking environments and how to obtain them
  781. X
  782. X%A Roy Hall
  783. X%B Illumination and Color in Computer Generated Imagery
  784. X%C New York
  785. X%D 1989
  786. X%I Springer-Verlag
  787. X
  788. X%A Timothy L. Kay
  789. X%A James T. Kajiya
  790. X%T Ray Tracing Complex Scenes
  791. X%J Computer Graphics
  792. X(SIGGRAPH '86 Proceedings)
  793. X%V 20
  794. X%N 4
  795. X%D Aug. 1986
  796. X%P 269-278
  797. X%K bounding volume
  798. X
  799. X%A Roman Kuchkuda
  800. X%T An Introduction to Ray Tracing
  801. X%B Theoretical Foundations of Computer Graphics and CAD
  802. X%E R.A. Earnshaw
  803. X%I Springer-Verlag
  804. X%C Berlin
  805. X%D 1988
  806. X%P 1039-1060
  807. X
  808. X%A J. P. Lewis
  809. X%T Algorithms for Solid Noise Synthesis
  810. X%J Computer Graphics
  811. X(SIGGRAPH '89 Proceedings)
  812. X%V 23
  813. X%N 3
  814. X%D August 1989
  815. X%P 263-270
  816. X
  817. X%A Don P. Mitchell
  818. X%T Generating Antialiased Images at Low Sampling Densities
  819. X%J Computer Graphics
  820. X(SIGGRAPH '87 Proceedings)
  821. X%V 21
  822. X%N 4
  823. X%D July 1987
  824. X%P 65-72
  825. X
  826. X%A F. Kenton Musgrave
  827. X%A Craig E. Kolb
  828. X%A Robert S. Mace
  829. X%T The Synthesis and Rendering of Eroded Fractal Terrains
  830. X%J Computer Graphics
  831. X(SIGGRAPH '89 Proceedings)
  832. X%V 23
  833. X%N 3
  834. X%D July 1989
  835. X%P 41-50
  836. X%Z info on efficiently ray tracing height fields
  837. X%K fractal, height fields
  838. X
  839. X%A Ken Perlin
  840. X%T An Image Synthesizer
  841. X%J Computer Graphics
  842. X(SIGGRAPH '85 Proceedings)
  843. X%V 19
  844. X%N 3
  845. X%D July 1985
  846. X%P 287-296
  847. X
  848. X%A David F. Rogers
  849. X%B Procedural Elements for Computer Graphics
  850. X%I McGraw-Hill
  851. X%C New York
  852. X%D 1985
  853. X%Z the only book on image synthesis, good summary of ray tracing
  854. X
  855. X%A John M. Snyder
  856. X%A Alan H. Barr
  857. X%T Ray Tracing Complex Models Containing Surface Tessellations
  858. X%J Computer Graphics
  859. X(SIGGRAPH '87 Proceedings)
  860. X%V 21
  861. X%N 4
  862. X%D July 1987
  863. X%P 119-128
  864. X%Z If you only read one paper before modifying rayshade, make it this one.
  865. X%K parametric surface, tessellation, 3D grid
  866. X
  867. X%A Turner Whitted
  868. X%T An Improved Illumination Model for Shaded Display
  869. X%J CACM
  870. X%V 23
  871. X%N 6
  872. X%D June 1980
  873. X%P 343-349
  874. X%Z the classic ray tracing paper
  875. END_OF_FILE
  876. if test 2965 -ne `wc -c <'References'`; then
  877.     echo shar: \"'References'\" unpacked with wrong size!
  878. fi
  879. # end of 'References'
  880. fi
  881. if test -f 'TODO' -a "${1}" != "-c" ; then 
  882.   echo shar: Will not clobber existing file \"'TODO'\"
  883. else
  884. echo shar: Extracting \"'TODO'\" \(1259 characters\)
  885. sed "s/^X//" >'TODO' <<'END_OF_FILE'
  886. XAdd CSG.
  887. X
  888. XMake "distributed ray tracing" implementation more complete.  Sample for
  889. Xdepth of field, gloss, etc.
  890. X
  891. XKeep track of maxt for a given ray and pass it to the various
  892. Xintersection routines.  For example, we can stop traversing a height
  893. Xfield grid if the ray hasn't hit the height field by the time we're
  894. X"maxt" along the ray.
  895. X
  896. XKeep track of the primitives hit for (at least a portion of) the ray
  897. Xtree.  When spawaning a new ray, check for intersection with the primitive
  898. Xlast hit by the corresponding ray in the saved tree.  If it hits, you have a
  899. Xvalue for "maxt" for the above.
  900. X
  901. XMake heightfields be stored in fixed-point, and take care of byte-ordering
  902. Xproblems so that height fields are transportable from machine to machine.
  903. X
  904. XImplement something similar to Jevans & Wyvill's adaptive subdivision scheme.
  905. X
  906. XAdd better antialiasing (e.g., Mitchell's paper).
  907. X
  908. XAdd a better way to do continue an interrupted trace.  There should be code
  909. Xin rayshade to find the number of the last line traced and start from
  910. Xthere.
  911. X
  912. XAdd an option to perform sorting during ray/List intersection tests so
  913. Xwe test objects roughly in order.
  914. X
  915. XImprove handling of input files (error messages, #include directives, etc.).
  916. X
  917. XHave workers pass statistics back to the supervisor.
  918. END_OF_FILE
  919. if test 1259 -ne `wc -c <'TODO'`; then
  920.     echo shar: \"'TODO'\" unpacked with wrong size!
  921. fi
  922. # end of 'TODO'
  923. fi
  924. if test ! -d 'doc' ; then
  925.     echo shar: Creating directory \"'doc'\"
  926.     mkdir 'doc'
  927. fi
  928. if test ! -d 'src' ; then
  929.     echo shar: Creating directory \"'src'\"
  930.     mkdir 'src'
  931. fi
  932. if test -f 'src/atmosphere.c' -a "${1}" != "-c" ; then 
  933.   echo shar: Will not clobber existing file \"'src/atmosphere.c'\"
  934. else
  935. echo shar: Extracting \"'src/atmosphere.c'\" \(2223 characters\)
  936. sed "s/^X//" >'src/atmosphere.c' <<'END_OF_FILE'
  937. X/*
  938. X * atmosphere.c
  939. X *
  940. X * Copyright (C) 1989, Craig E. Kolb
  941. X *
  942. X * This software may be freely copied, modified, and redistributed,
  943. X * provided that this copyright notice is preserved on all copies.
  944. X *
  945. X * There is no warranty or other guarantee of fitness for this software,
  946. X * it is provided solely .  Bug reports or fixes may be sent
  947. X * to the author, who may or may not act on them as he desires.
  948. X *
  949. X * You may not include this software in a program or other software product
  950. X * without supplying the source, or without informing the end-user that the
  951. X * source is available for no extra charge.
  952. X *
  953. X * If you modify this software, you should include a notice giving the
  954. X * name of the person performing the modification, the date of modification,
  955. X * and the reason for such modification.
  956. X *
  957. X * $Id: atmosphere.c,v 3.0 89/10/27 02:05:46 craig Exp $
  958. X *
  959. X * $Log:    atmosphere.c,v $
  960. X * Revision 3.0  89/10/27  02:05:46  craig
  961. X * Baseline for first official release.
  962. X * 
  963. X */
  964. X#include <stdio.h>
  965. X#include <math.h>
  966. X#include "typedefs.h"
  967. X#include "constants.h"
  968. X#include "funcdefs.h"
  969. X
  970. XFog *GlobalFog;
  971. XMist *GlobalMist;
  972. X
  973. X/*
  974. X * Add fog to the given color.
  975. X */
  976. XComputeFog(fog, dist, color)
  977. XFog *fog;
  978. Xdouble dist;
  979. XColor *color;
  980. X{
  981. X    double atten;
  982. X
  983. X    atten = LNHALF * dist * fog->trans;
  984. X    if (atten < -10.)
  985. X        atten = 0.;
  986. X    else
  987. X        atten = exp(atten);
  988. X    blend_color(color, &fog->color, atten, 1. - atten);
  989. X}
  990. X
  991. X/*
  992. X * Add low-altitude mist to the given color.
  993. X */
  994. XComputeMist(mist, origin, hit, dist, color)
  995. XMist *mist;
  996. XVector *origin, *hit;
  997. Xdouble dist;
  998. XColor *color;
  999. X{
  1000. X    double deltaZ, d, atten;
  1001. X
  1002. X    deltaZ = mist->scale * (hit->z - origin->z);
  1003. X    if (abs(deltaZ) > EPSILON)
  1004. X        d = (exp(-origin->z*mist->scale + mist->zero) -
  1005. X                exp(-hit->z*mist->scale + mist->zero)) / deltaZ;
  1006. X    else
  1007. X        d = exp(-hit->z*mist->scale + mist->zero);
  1008. X    d *= LNHALF * dist;
  1009. X    atten =  d /  mist->trans.r;
  1010. X    atten = (atten < -10. ? (0.) : exp(atten));
  1011. X    color->r = atten*color->r + (1. - atten)*mist->color.r;
  1012. X
  1013. X    atten =  d /  mist->trans.g;
  1014. X    atten = (atten < -10. ? (0.) : exp(atten));
  1015. X    color->g = atten*color->g + (1. - atten)*mist->color.g;
  1016. X
  1017. X    atten =  d /  mist->trans.b;
  1018. X    atten = (atten < -10. ? (0.) : exp(atten));
  1019. X    color->b = atten*color->b + (1. - atten)*mist->color.b;
  1020. X}
  1021. END_OF_FILE
  1022. if test 2223 -ne `wc -c <'src/atmosphere.c'`; then
  1023.     echo shar: \"'src/atmosphere.c'\" unpacked with wrong size!
  1024. fi
  1025. # end of 'src/atmosphere.c'
  1026. fi
  1027. if test -f 'src/box.c' -a "${1}" != "-c" ; then 
  1028.   echo shar: Will not clobber existing file \"'src/box.c'\"
  1029. else
  1030. echo shar: Extracting \"'src/box.c'\" \(3148 characters\)
  1031. sed "s/^X//" >'src/box.c' <<'END_OF_FILE'
  1032. X/*
  1033. X * box.c
  1034. X *
  1035. X * Copyright (C) 1989, Craig E. Kolb
  1036. X *
  1037. X * This software may be freely copied, modified, and redistributed,
  1038. X * provided that this copyright notice is preserved on all copies.
  1039. X *
  1040. X * There is no warranty or other guarantee of fitness for this software,
  1041. X * it is provided solely .  Bug reports or fixes may be sent
  1042. X * to the author, who may or may not act on them as he desires.
  1043. X *
  1044. X * You may not include this software in a program or other software product
  1045. X * without supplying the source, or without informing the end-user that the
  1046. X * source is available for no extra charge.
  1047. X *
  1048. X * If you modify this software, you should include a notice giving the
  1049. X * name of the person performing the modification, the date of modification,
  1050. X * and the reason for such modification.
  1051. X *
  1052. X * $Id: box.c,v 3.0 89/10/27 02:05:47 craig Exp $
  1053. X *
  1054. X * $Log:    box.c,v $
  1055. X * Revision 3.0  89/10/27  02:05:47  craig
  1056. X * Baseline for first official release.
  1057. X * 
  1058. X */
  1059. X#include <math.h>
  1060. X#include <stdio.h>
  1061. X#include "constants.h"
  1062. X#include "typedefs.h"
  1063. X#include "funcdefs.h"
  1064. X
  1065. XObject *
  1066. Xmakbox(surf, x, y, z, xs, ys, zs)
  1067. Xchar *surf;
  1068. Xdouble x, y, z, xs, ys, zs;
  1069. X{
  1070. X    Box          *box;
  1071. X    Primitive *prim;
  1072. X    Object *newobj;
  1073. X    extern int Quiet, yylineno;
  1074. X
  1075. X    if (xs < EPSILON || ys < EPSILON || zs < EPSILON) {
  1076. X        if (!Quiet)
  1077. X            fprintf(stderr,"Degenerate box (line %d)\n",yylineno);
  1078. X        return (Object *)0;
  1079. X    }
  1080. X    prim = mallocprim();
  1081. X    prim->surf = find_surface(surf);
  1082. X    newobj = new_object(NULL, BOX, (char *)prim, (Trans *)NULL);
  1083. X    prim->type = BOX;
  1084. X    box = (Box *)Malloc(sizeof(Box));
  1085. X    prim->objpnt.p_box = box;
  1086. X    box->bounds[LOW][X] = x - xs;
  1087. X    box->bounds[HIGH][X] = x + xs;
  1088. X    box->bounds[LOW][Y] = y - ys;
  1089. X    box->bounds[HIGH][Y] = y + ys;
  1090. X    box->bounds[LOW][Z] = z - zs;
  1091. X    box->bounds[HIGH][Z] = z + zs;
  1092. X    return newobj;
  1093. X}
  1094. X
  1095. Xdouble
  1096. Xintbox(pos, ray, obj)
  1097. XVector *ray;    /* ray vector */
  1098. XVector *pos;    /* origin of ray */
  1099. XPrimitive *obj;    /* box description */
  1100. X{
  1101. X    Ray tmpray;
  1102. X    extern unsigned long BVTests, primtests[];
  1103. X
  1104. X    /*
  1105. X     * IntBounds will increment BVTests, even though we're
  1106. X     * not really doing a BV intersection test.
  1107. X     */
  1108. X    primtests[BOX]++;
  1109. X    BVTests--;
  1110. X    tmpray.pos = *pos;
  1111. X    tmpray.dir = *ray;
  1112. X    return IntBounds(&tmpray, obj->objpnt.p_box->bounds);
  1113. X}
  1114. X
  1115. Xnrmbox(pos, obj, nrm)
  1116. XVector           *pos, *nrm;    /* point of intersection */
  1117. XPrimitive       *obj;    /* box description */
  1118. X{
  1119. X    Box          *box;
  1120. X
  1121. X    box = obj->objpnt.p_box;
  1122. X    nrm->x = nrm->y = nrm->z = 0.;
  1123. X
  1124. X    if (equal(pos->x, box->bounds[HIGH][X]))
  1125. X        nrm->x = 1.;
  1126. X    else if (equal(pos->x, box->bounds[LOW][X]))
  1127. X        nrm->x = -1.;
  1128. X    else if (equal(pos->y, box->bounds[HIGH][Y]))
  1129. X        nrm->y = 1.;
  1130. X    else if (equal(pos->y, box->bounds[LOW][Y]))
  1131. X        nrm->y = -1.;
  1132. X    else if (equal(pos->z, box->bounds[HIGH][Z]))
  1133. X        nrm->z = 1.;
  1134. X    else if (equal(pos->z, box->bounds[LOW][Z]))
  1135. X        nrm->z = -1.;
  1136. X    else
  1137. X        fprintf(stderr,"Nrmbox: confusion!\n");
  1138. X}
  1139. X
  1140. Xboxextent(o, bounds)
  1141. XPrimitive *o;
  1142. Xdouble bounds[2][3];
  1143. X{
  1144. X    Box *b = o->objpnt.p_box;
  1145. X
  1146. X    bounds[LOW][X] = b->bounds[LOW][X];
  1147. X    bounds[HIGH][X] = b->bounds[HIGH][X];
  1148. X    bounds[LOW][Y] = b->bounds[LOW][Y];
  1149. X    bounds[HIGH][Y] = b->bounds[HIGH][Y];
  1150. X    bounds[LOW][Z] = b->bounds[LOW][Z];
  1151. X    bounds[HIGH][Z] = b->bounds[HIGH][Z];
  1152. X}
  1153. END_OF_FILE
  1154. if test 3148 -ne `wc -c <'src/box.c'`; then
  1155.     echo shar: \"'src/box.c'\" unpacked with wrong size!
  1156. fi
  1157. # end of 'src/box.c'
  1158. fi
  1159. if test -f 'src/constants.h' -a "${1}" != "-c" ; then 
  1160.   echo shar: Will not clobber existing file \"'src/constants.h'\"
  1161. else
  1162. echo shar: Extracting \"'src/constants.h'\" \(2403 characters\)
  1163. sed "s/^X//" >'src/constants.h' <<'END_OF_FILE'
  1164. X/*
  1165. X * constants.h
  1166. X *
  1167. X * Copyright (C) 1989, Craig E. Kolb
  1168. X *
  1169. X * This software may be freely copied, modified, and redistributed,
  1170. X * provided that this copyright notice is preserved on all copies.
  1171. X *
  1172. X * There is no warranty or other guarantee of fitness for this software,
  1173. X * it is provided solely .  Bug reports or fixes may be sent
  1174. X * to the author, who may or may not act on them as he desires.
  1175. X *
  1176. X * You may not include this software in a program or other software product
  1177. X * without supplying the source, or without informing the end-user that the
  1178. X * source is available for no extra charge.
  1179. X *
  1180. X * If you modify this software, you should include a notice giving the
  1181. X * name of the person performing the modification, the date of modification,
  1182. X * and the reason for such modification.
  1183. X *
  1184. X * $Id: constants.h,v 3.0 89/10/27 02:05:48 craig Exp $
  1185. X *
  1186. X * $Log:    constants.h,v $
  1187. X * Revision 3.0  89/10/27  02:05:48  craig
  1188. X * Baseline for first official release.
  1189. X * 
  1190. X */
  1191. X
  1192. X#define LIGHTS        10        /* Max # of lights */
  1193. X
  1194. X/*
  1195. X * Primitive type constants.  When adding primitives, insert *before*
  1196. X * "LIST" and increment LIST and GRID values, otherwise arrays of
  1197. X * intersection/normal/extent routines in intersect.c won't be indexed
  1198. X * correctly.
  1199. X */
  1200. X#define SPHERE        0
  1201. X#define BOX        1
  1202. X#define TRIANGLE    2
  1203. X#define SUPERQ        3
  1204. X#define PLANE        4
  1205. X#define CYL        5
  1206. X#define POLY        6
  1207. X#define PHONGTRI    7
  1208. X#define CONE        8
  1209. X#define HF        9
  1210. X#define LIST        10
  1211. X#define GRID        11
  1212. X
  1213. X#define PRIMTYPES    10    /* # of types of primitives */
  1214. X
  1215. X#define TRUE        1
  1216. X#define FALSE        0
  1217. X
  1218. X/*
  1219. X * Used to make indices into bounding box arrays more readable.
  1220. X */
  1221. X#define X    0
  1222. X#define Y    1
  1223. X#define Z    2
  1224. X#define LOW    0
  1225. X#define HIGH    1
  1226. X
  1227. X/*
  1228. X * Light source types
  1229. X */
  1230. X#define LOCAL        (char)1
  1231. X#define DIRECTIONAL    (char)2
  1232. X#define EXTENDED    (char)3
  1233. X
  1234. X/*
  1235. X * Various useful constants and macros.
  1236. X */
  1237. X#define    PI        3.14159265358979323846
  1238. X#define deg2rad(x)    (double)(PI * x / 180.)
  1239. X#define LNHALF        (-.69314718)
  1240. X/*
  1241. X * Minimum vector length
  1242. X */
  1243. X#define EPSILON        (double)0.00001
  1244. X
  1245. X/*
  1246. X * Maximum intersection-point distance.  (Making the "world" a sphere of radius
  1247. X * FAR_AWAY centered at eyep.)
  1248. X */
  1249. X#define FAR_AWAY        1.0E+14
  1250. X
  1251. X/*
  1252. X * Constants used in triangle & polygon intersection tests.
  1253. X */
  1254. X#define XNORMAL        (char)0
  1255. X#define YNORMAL        (char)1
  1256. X#define ZNORMAL        (char)2
  1257. X
  1258. X/*
  1259. X * Constants for Stereo mode
  1260. X */
  1261. X#define LEFT        1
  1262. X#define RIGHT        2
  1263. X
  1264. X#ifndef NULL
  1265. X#    define NULL 0
  1266. X#endif
  1267. X
  1268. X#define UNSET        -1
  1269. END_OF_FILE
  1270. if test 2403 -ne `wc -c <'src/constants.h'`; then
  1271.     echo shar: \"'src/constants.h'\" unpacked with wrong size!
  1272. fi
  1273. # end of 'src/constants.h'
  1274. fi
  1275. if test -f 'src/defaults.h' -a "${1}" != "-c" ; then 
  1276.   echo shar: Will not clobber existing file \"'src/defaults.h'\"
  1277. else
  1278. echo shar: Extracting \"'src/defaults.h'\" \(1642 characters\)
  1279. sed "s/^X//" >'src/defaults.h' <<'END_OF_FILE'
  1280. X/*
  1281. X * defaults.h
  1282. X *
  1283. X * Copyright (C) 1989, Craig E. Kolb
  1284. X *
  1285. X * This software may be freely copied, modified, and redistributed,
  1286. X * provided that this copyright notice is preserved on all copies.
  1287. X *
  1288. X * There is no warranty or other guarantee of fitness for this software,
  1289. X * it is provided solely .  Bug reports or fixes may be sent
  1290. X * to the author, who may or may not act on them as he desires.
  1291. X *
  1292. X * You may not include this software in a program or other software product
  1293. X * without supplying the source, or without informing the end-user that the
  1294. X * source is available for no extra charge.
  1295. X *
  1296. X * If you modify this software, you should include a notice giving the
  1297. X * name of the person performing the modification, the date of modification,
  1298. X * and the reason for such modification.
  1299. X *
  1300. X * $Id: defaults.h,v 3.0 89/10/27 02:05:49 craig Exp $
  1301. X *
  1302. X * $Log:    defaults.h,v $
  1303. X * Revision 3.0  89/10/27  02:05:49  craig
  1304. X * Baseline for first official release.
  1305. X * 
  1306. X */
  1307. X
  1308. X#define DEFLIGHTSAMPLES    4    /* sqrt of number of shadow rays per pixel */
  1309. X
  1310. X#define XRESOLUTION    512        /* Default screen size (pixels) */
  1311. X#define YRESOLUTION    512
  1312. X#define DEFCUTOFF    0.001        /* Default tree cutoff value */
  1313. X#define MAXLEVEL    3        /* Maximum ray tree depth. */
  1314. X#define PIXEL_DIV    1        /* Maximum pixel subdivision factor */
  1315. X#define HFOV        45        /* Field-of-view */
  1316. X#define EYEX        0        /* Eye position */
  1317. X#define EYEY        20
  1318. X#define EYEZ        0
  1319. X#define LOOKX        0        /* Look point */
  1320. X#define LOOKY        0
  1321. X#define LOOKZ        0
  1322. X#define UPX        0        /* Up vector */
  1323. X#define UPY        0
  1324. X#define UPZ        1
  1325. X
  1326. X#define DEFREDCONT    0.25        /* Default contrast threshold values. */
  1327. X#define DEFGREENCONT    0.2
  1328. X#define DEFBLUECONT    0.4
  1329. END_OF_FILE
  1330. if test 1642 -ne `wc -c <'src/defaults.h'`; then
  1331.     echo shar: \"'src/defaults.h'\" unpacked with wrong size!
  1332. fi
  1333. # end of 'src/defaults.h'
  1334. fi
  1335. if test -f 'src/input_lex.l' -a "${1}" != "-c" ; then 
  1336.   echo shar: Will not clobber existing file \"'src/input_lex.l'\"
  1337. else
  1338. echo shar: Extracting \"'src/input_lex.l'\" \(2960 characters\)
  1339. sed "s/^X//" >'src/input_lex.l' <<'END_OF_FILE'
  1340. X/* input_lex.l                                    */
  1341. X/*                                        */
  1342. X/* Copyright (C) 1989, Craig E. Kolb                        */
  1343. X/*                                        */
  1344. X/* This software may be freely copied, modified, and redistributed,        */
  1345. X/* provided that this copyright notice is preserved on all copies.        */
  1346. X/*                                         */
  1347. X/* There is no warranty or other guarantee of fitness for this software,    */
  1348. X/* it is provided solely "as is".  Bug reports or fixes may be sent        */
  1349. X/* to the author, who may or may not act on them as he desires.            */
  1350. X/*                                        */
  1351. X/* You may not include this software in a program or other software product */
  1352. X/* without supplying the source, or without informing the end-user that the */
  1353. X/* source is available for no extra charge.                    */
  1354. X/*                                        */
  1355. X/* $Id: input_lex.l,v 3.0 89/10/27 02:05:52 craig Exp $ */
  1356. X%{
  1357. X#include <stdio.h>
  1358. X#ifdef SYSV
  1359. X#include <string.h>
  1360. X#else
  1361. X#include <strings.h>
  1362. X#endif
  1363. X#include "typedefs.h"
  1364. X#include "y.tab.h"
  1365. Xdouble atof();
  1366. Xchar *strsave();
  1367. X%}
  1368. Xalpha    [a-zA-Z]
  1369. Xspecial    [\.\_-]
  1370. Xdigit    [0-9]
  1371. Xexp    [Ee][-+]?{digit}+
  1372. Xstring    ({alpha}|"/")({alpha}|{digit}|{special}|"/")*
  1373. X%p 3000
  1374. X%%
  1375. X" "            ;
  1376. X\t            ;
  1377. X\n            ;
  1378. X"/*"            {skipcomments();}
  1379. Xadaptive        {return(tADAPTIVE);}
  1380. Xbackground        {return(tBACKGROUND);}
  1381. Xblotch            {return(tBLOTCH);}
  1382. Xbox            {return(tBOX);}
  1383. Xbump            {return(tBUMP);}
  1384. Xchecker            {return(tCHECKER);}
  1385. Xcone            {return(tCONE);}
  1386. Xcontrast        {return(tCONTRAST);}
  1387. Xcutoff            {return(tCUTOFF);}
  1388. Xcylinder        {return(tCYL);}
  1389. Xdefend            {return(tENDDEF);}
  1390. Xdefine            {return(tSTARTDEF);}
  1391. Xdirectional        {return(tDIRECTIONAL);}
  1392. Xendfile            {return(tENDFILE);}
  1393. Xextended        {return(tEXTENDED);}
  1394. Xeyep            {return(tEYEP);}
  1395. Xfbm            {return(tFBM);}
  1396. Xfbmbump            {return(tFBMBUMP);}
  1397. Xfog            {return(tFOG);}
  1398. Xfov            {return(tFOV);}
  1399. Xgrid            {return(tGRID);}
  1400. Xheightfield        {return(tHEIGHTFIELD);}
  1401. Xjittered        {return(tJITTERED);}
  1402. Xlight            {return(tLIGHT);}
  1403. Xlist            {return(tLIST);}
  1404. Xlookp            {return(tLOOKP);}
  1405. Xmarble            {return(tMARBLE);}
  1406. Xmaxdepth        {return(tMAXDEPTH);}
  1407. Xmist            {return(tMIST);}
  1408. Xobject            {return(tOBJECT);}
  1409. Xoutfile            {return(tOUTFILE);}
  1410. Xplane            {return(tPLANE);}
  1411. Xpoint            {return(tPOINT);}
  1412. Xpoly            {return(tPOLY);}
  1413. Xresolution        {return(tRESOLUTION);}
  1414. Xrotate            {return(tROTATE);}
  1415. Xsamples            {return(tSAMPLES);}
  1416. Xscale            {return(tSCALE);}
  1417. Xscreen            {return(tSCREEN);}
  1418. Xsphere            {return(tSPHERE);}
  1419. Xsuperq            {return(tSUPERQ);}
  1420. Xsurface            {return(tSURFACE);}
  1421. Xtexture            {return(tTEXTURE);}
  1422. Xtransform        {return(tTRANSFORM);}
  1423. Xtranslate        {return(tTRANSLATE);}
  1424. Xtriangle        {return(tTRIANGLE);}
  1425. Xup            {return(tUP);}
  1426. Xwood            {return(tWOOD);}
  1427. X{string}        {yylval.c = strsave(yytext);
  1428. X                return(tSTRING);}
  1429. X[+-]?{digit}+        {yylval.i = atoi(yytext);
  1430. X                return(tINT);}
  1431. X
  1432. X[+-]?{digit}+"."{digit}*({exp})? |
  1433. X[+-]?{digit}*"."{digit}+({exp})? |
  1434. X[+-]?{digit}+{exp}        {yylval.d = atof(yytext); return(tFLOAT);}
  1435. X
  1436. X.            {return yytext[0];}
  1437. X
  1438. X%%
  1439. Xyywrap() {return(1);}
  1440. X/*
  1441. X * Skip over comments.
  1442. X */
  1443. Xskipcomments()
  1444. X{
  1445. X    char c;
  1446. X
  1447. X    while (1) {
  1448. X        while (input() != '*')
  1449. X            ;
  1450. X        if ((c = input()) == '/')
  1451. X            return;
  1452. X        unput(c);
  1453. X    }
  1454. X}
  1455. END_OF_FILE
  1456. if test 2960 -ne `wc -c <'src/input_lex.l'`; then
  1457.     echo shar: \"'src/input_lex.l'\" unpacked with wrong size!
  1458. fi
  1459. # end of 'src/input_lex.l'
  1460. fi
  1461. if test -f 'src/memory.c' -a "${1}" != "-c" ; then 
  1462.   echo shar: Will not clobber existing file \"'src/memory.c'\"
  1463. else
  1464. echo shar: Extracting \"'src/memory.c'\" \(1596 characters\)
  1465. sed "s/^X//" >'src/memory.c' <<'END_OF_FILE'
  1466. X/*
  1467. X * memory.c
  1468. X *
  1469. X * Copyright (C) 1989, Craig E. Kolb
  1470. X *
  1471. X * This software may be freely copied, modified, and redistributed,
  1472. X * provided that this copyright notice is preserved on all copies.
  1473. X *
  1474. X * There is no warranty or other guarantee of fitness for this software,
  1475. X * it is provided solely .  Bug reports or fixes may be sent
  1476. X * to the author, who may or may not act on them as he desires.
  1477. X *
  1478. X * You may not include this software in a program or other software product
  1479. X * without supplying the source, or without informing the end-user that the
  1480. X * source is available for no extra charge.
  1481. X *
  1482. X * If you modify this software, you should include a notice giving the
  1483. X * name of the person performing the modification, the date of modification,
  1484. X * and the reason for such modification.
  1485. X *
  1486. X * $Id: memory.c,v 3.0 89/10/27 02:05:56 craig Exp $
  1487. X *
  1488. X * $Log:    memory.c,v $
  1489. X * Revision 3.0  89/10/27  02:05:56  craig
  1490. X * Baseline for first official release.
  1491. X * 
  1492. X */
  1493. X#include <stdio.h>
  1494. X#include "typedefs.h"
  1495. X#include "funcdefs.h"
  1496. X
  1497. Xunsigned long TotalAllocated;
  1498. X
  1499. Xchar *
  1500. XMalloc(bytes)
  1501. Xunsigned bytes;
  1502. X{
  1503. X    char *res, *malloc();
  1504. X
  1505. X    TotalAllocated += bytes;
  1506. X
  1507. X    res = malloc(bytes);
  1508. X    if (res == (char *)0) {
  1509. X        fprintf(stderr,"Out of memory trying to allocate %d bytes.\n");
  1510. X        exit(0);
  1511. X    }
  1512. X    return res;
  1513. X}
  1514. X
  1515. Xchar *
  1516. XCalloc(nelem, elen)
  1517. Xunsigned nelem, elen;
  1518. X{
  1519. X    char *res;
  1520. X
  1521. X    res = Malloc(nelem*elen);
  1522. X#ifdef SYSV
  1523. X    memset(res, (char)0, nelem*elen);
  1524. X#else
  1525. X    bzero(res, nelem*elen);
  1526. X#endif
  1527. X    return res;
  1528. X}
  1529. X
  1530. XPrintMemoryStats()
  1531. X{
  1532. X    extern FILE *fstats;
  1533. X
  1534. X    fprintf(fstats,"Total memory allocated:\t\t%d bytes\n",TotalAllocated);
  1535. X}
  1536. END_OF_FILE
  1537. if test 1596 -ne `wc -c <'src/memory.c'`; then
  1538.     echo shar: \"'src/memory.c'\" unpacked with wrong size!
  1539. fi
  1540. # end of 'src/memory.c'
  1541. fi
  1542. if test -f 'src/patchlevel.h' -a "${1}" != "-c" ; then 
  1543.   echo shar: Will not clobber existing file \"'src/patchlevel.h'\"
  1544. else
  1545. echo shar: Extracting \"'src/patchlevel.h'\" \(21 characters\)
  1546. sed "s/^X//" >'src/patchlevel.h' <<'END_OF_FILE'
  1547. X#define PATCHLEVEL 0
  1548. END_OF_FILE
  1549. if test 21 -ne `wc -c <'src/patchlevel.h'`; then
  1550.     echo shar: \"'src/patchlevel.h'\" unpacked with wrong size!
  1551. fi
  1552. # end of 'src/patchlevel.h'
  1553. fi
  1554. if test -f 'src/plane.c' -a "${1}" != "-c" ; then 
  1555.   echo shar: Will not clobber existing file \"'src/plane.c'\"
  1556. else
  1557. echo shar: Extracting \"'src/plane.c'\" \(2370 characters\)
  1558. sed "s/^X//" >'src/plane.c' <<'END_OF_FILE'
  1559. X/*
  1560. X * plane.c
  1561. X *
  1562. X * Copyright (C) 1989, Craig E. Kolb
  1563. X *
  1564. X * This software may be freely copied, modified, and redistributed,
  1565. X * provided that this copyright notice is preserved on all copies.
  1566. X *
  1567. X * There is no warranty or other guarantee of fitness for this software,
  1568. X * it is provided solely .  Bug reports or fixes may be sent
  1569. X * to the author, who may or may not act on them as he desires.
  1570. X *
  1571. X * You may not include this software in a program or other software product
  1572. X * without supplying the source, or without informing the end-user that the
  1573. X * source is available for no extra charge.
  1574. X *
  1575. X * If you modify this software, you should include a notice giving the
  1576. X * name of the person performing the modification, the date of modification,
  1577. X * and the reason for such modification.
  1578. X *
  1579. X * $Id: plane.c,v 3.0 89/10/27 02:05:59 craig Exp $
  1580. X *
  1581. X * $Log:    plane.c,v $
  1582. X * Revision 3.0  89/10/27  02:05:59  craig
  1583. X * Baseline for first official release.
  1584. X * 
  1585. X */
  1586. X#include <stdio.h>
  1587. X#include "constants.h"
  1588. X#include "typedefs.h"
  1589. X#include "funcdefs.h"
  1590. X
  1591. X/*
  1592. X * create plane Primitive
  1593. X */
  1594. XObject *
  1595. Xmakplane(surf, norm, pos)
  1596. Xchar *surf;
  1597. XVector *norm, *pos;
  1598. X{
  1599. X    Plane    *plane;
  1600. X    Vector tmpnrm;
  1601. X    Object *newobj;
  1602. X    Primitive *prim;
  1603. X    extern int Quiet, yylineno;
  1604. X
  1605. X    tmpnrm = *norm;
  1606. X    if (normalize(&tmpnrm) == 0.) {
  1607. X        if (!Quiet)
  1608. X            fprintf(stderr, "Degenerate plane normal (line %d)\n",
  1609. X                            yylineno);
  1610. X        return (Object *)0;
  1611. X    }
  1612. X    prim = mallocprim();
  1613. X    prim->surf = find_surface(surf);
  1614. X    prim->type = PLANE;
  1615. X    newobj = new_object(NULL, PLANE, (char *)prim, (Trans *)NULL);
  1616. X    plane = (Plane *)Malloc(sizeof(Plane));
  1617. X    prim->objpnt.p_plane = plane;
  1618. X    plane->norm = tmpnrm;
  1619. X    plane->d = dotp(&plane->norm, pos);
  1620. X
  1621. X    return newobj;
  1622. X}
  1623. X
  1624. Xdouble
  1625. Xintplane(pos, ray, obj)
  1626. XVector *pos;
  1627. XVector *ray;
  1628. XPrimitive *obj;
  1629. X{
  1630. X    Plane *plane;
  1631. X    double denom, dist;
  1632. X    extern unsigned long primtests[];
  1633. X
  1634. X    primtests[PLANE]++;
  1635. X    plane = obj->objpnt.p_plane;
  1636. X
  1637. X    denom = dotp(&plane->norm, ray);
  1638. X    if (denom == 0.)
  1639. X        return 0.;
  1640. X    dist = (plane->d - dotp(&plane->norm, pos)) / denom;
  1641. X    return (dist > FAR_AWAY ? 0. : dist);
  1642. X}
  1643. X
  1644. X/*ARGSUSED*/
  1645. Xnrmplane(pos, obj, nrm)
  1646. XVector *pos, *nrm;
  1647. XPrimitive *obj;
  1648. X{
  1649. X    *nrm = obj->objpnt.p_plane->norm;
  1650. X}
  1651. X
  1652. X/*ARGSUSED*/
  1653. Xplaneextent(o, bounds)
  1654. XPrimitive *o;
  1655. Xdouble bounds[2][3];
  1656. X{
  1657. X    /*
  1658. X     * Planes are unbounded by nature.  minx > maxx signifies
  1659. X     * this.
  1660. X     */
  1661. X    bounds[LOW][X] = 1.0;
  1662. X    bounds[HIGH][X] = -1.0;
  1663. X}
  1664. END_OF_FILE
  1665. if test 2370 -ne `wc -c <'src/plane.c'`; then
  1666.     echo shar: \"'src/plane.c'\" unpacked with wrong size!
  1667. fi
  1668. # end of 'src/plane.c'
  1669. fi
  1670. if test -f 'src/raymath.c' -a "${1}" != "-c" ; then 
  1671.   echo shar: Will not clobber existing file \"'src/raymath.c'\"
  1672. else
  1673. echo shar: Extracting \"'src/raymath.c'\" \(3147 characters\)
  1674. sed "s/^X//" >'src/raymath.c' <<'END_OF_FILE'
  1675. X/*
  1676. X * raymath.c
  1677. X *
  1678. X * Copyright (C) 1989, Craig E. Kolb
  1679. X *
  1680. X * This software may be freely copied, modified, and redistributed,
  1681. X * provided that this copyright notice is preserved on all copies.
  1682. X *
  1683. X * There is no warranty or other guarantee of fitness for this software,
  1684. X * it is provided solely .  Bug reports or fixes may be sent
  1685. X * to the author, who may or may not act on them as he desires.
  1686. X *
  1687. X * You may not include this software in a program or other software product
  1688. X * without supplying the source, or without informing the end-user that the
  1689. X * source is available for no extra charge.
  1690. X *
  1691. X * If you modify this software, you should include a notice giving the
  1692. X * name of the person performing the modification, the date of modification,
  1693. X * and the reason for such modification.
  1694. X *
  1695. X * $Id: raymath.c,v 3.0 89/10/27 02:06:01 craig Exp $
  1696. X *
  1697. X * $Log:    raymath.c,v $
  1698. X * Revision 3.0  89/10/27  02:06:01  craig
  1699. X * Baseline for first official release.
  1700. X * 
  1701. X */
  1702. X#include <math.h>
  1703. X#include "typedefs.h"
  1704. X#include "constants.h"
  1705. X#include "funcdefs.h"
  1706. X
  1707. X/*
  1708. X * Normalize a vector, return original length.
  1709. X */
  1710. Xdouble
  1711. Xnormalize(a)
  1712. Xregister Vector *a;
  1713. X{
  1714. X    double d;
  1715. X
  1716. X    d = sqrt(a->x*a->x + a->y*a->y + a->z*a->z);
  1717. X    if(d == 0.)
  1718. X        return 0.;
  1719. X    a->x /= d;
  1720. X    a->y /= d;
  1721. X    a->z /= d;
  1722. X    return d;
  1723. X}
  1724. X
  1725. X/*
  1726. X * Compute cross-product of a and b, place normalized result in o.  Returns
  1727. X * length of result before normalization.
  1728. X */
  1729. Xdouble
  1730. Xcrossp(o, a, b)
  1731. XVector *o, *a, *b;
  1732. X{
  1733. X    rawcrossp(o, a, b);
  1734. X    return normalize(o);
  1735. X}
  1736. X
  1737. X/*
  1738. X * Compute cross-product of a and b, place result in o.
  1739. X */
  1740. Xrawcrossp(o, a, b)
  1741. XVector *o, *a, *b;
  1742. X{
  1743. X    o->x = (a->y * b->z) - (a->z * b->y);
  1744. X    o->y = (a->z * b->x) - (a->x * b->z);
  1745. X    o->z = (a->x * b->y) - (a->y * b->x);
  1746. X}
  1747. X
  1748. X/*
  1749. X * Calculate direction of refracted ray using Heckbert's formula.  Returns TRUE
  1750. X * if a total internal reflection occurs.
  1751. X */
  1752. Xrefract(dir, from_index, to_index, I, N, cos1)
  1753. Xdouble from_index, to_index, cos1;
  1754. XVector *dir, I, N;
  1755. X{
  1756. X    double kn, cos2, k;
  1757. X
  1758. X    if (cos1 < 0.) {
  1759. X        /*
  1760. X         * Hit the 'backside' of a surface -- flip the
  1761. X         * normal.
  1762. X         */
  1763. X        N.x = -N.x;
  1764. X        N.y = -N.y;
  1765. X        N.z = -N.z;
  1766. X        cos1 = -cos1;
  1767. X    }
  1768. X
  1769. X    kn = from_index / to_index;
  1770. X    cos2 = 1. - kn*kn*(1. - cos1*cos1);
  1771. X    if (cos2 < 0.)
  1772. X        return TRUE;        /* Total internal reflection. */
  1773. X    k = kn * cos1 - sqrt(cos2);
  1774. X    veccomb(kn, I, k, N, dir);
  1775. X    return FALSE;
  1776. X}
  1777. X
  1778. X#ifdef DUMB_CPP
  1779. X/*
  1780. X * Return difference between two vectors.
  1781. X */
  1782. Xvecsub(a, b, res)
  1783. XVector a, b, *res;
  1784. X{
  1785. X    res->x = a.x - b.x;
  1786. X    res->y = a.y - b.y;
  1787. X    res->z = a.z - b.z;
  1788. X}
  1789. X
  1790. X/*
  1791. X * Return sum of two vectors.
  1792. X */
  1793. Xvecadd(a, b, res)
  1794. XVector a, b, *res;
  1795. X{
  1796. X    res->x = a.x + b.x;
  1797. X    res->y = a.y + b.y;
  1798. X    res->z = a.z + b.z;
  1799. X}
  1800. X
  1801. X/*
  1802. X * Compute scalar product of a vector.
  1803. X */
  1804. Xscalar_prod(scale, vec, res)
  1805. Xdouble scale;
  1806. XVector vec, *res;
  1807. X{
  1808. X    res->x = vec.x * scale;
  1809. X    res->y = vec.y * scale;
  1810. X    res->z = vec.z * scale;
  1811. X}
  1812. X
  1813. Xveccomb(s1, v1, s2, v2, res)
  1814. Xdouble s1, s2;
  1815. XVector v1, v2, *res;
  1816. X{
  1817. X    res->x = s1 * v1.x + s2 * v2.x;
  1818. X    res->y = s1 * v1.y + s2 * v2.y;
  1819. X    res->z = s1 * v1.z + s2 * v2.z;
  1820. X}
  1821. X
  1822. Xaddscaledvec(v1, s, v2, res)
  1823. XVector v1, v2, *res;
  1824. Xdouble s;
  1825. X{
  1826. X    res->x = v1.x + s * v2.x;
  1827. X    res->y = v1.y + s * v2.y;
  1828. X    res->z = v1.z + s * v2.z;
  1829. X}
  1830. X#endif
  1831. END_OF_FILE
  1832. if test 3147 -ne `wc -c <'src/raymath.c'`; then
  1833.     echo shar: \"'src/raymath.c'\" unpacked with wrong size!
  1834. fi
  1835. # end of 'src/raymath.c'
  1836. fi
  1837. if test -f 'src/raytrace.h' -a "${1}" != "-c" ; then 
  1838.   echo shar: Will not clobber existing file \"'src/raytrace.h'\"
  1839. else
  1840. echo shar: Extracting \"'src/raytrace.h'\" \(1649 characters\)
  1841. sed "s/^X//" >'src/raytrace.h' <<'END_OF_FILE'
  1842. X/*
  1843. X * raytrace.h
  1844. X *
  1845. X * Copyright (C) 1989, Craig E. Kolb
  1846. X *
  1847. X * This software may be freely copied, modified, and redistributed,
  1848. X * provided that this copyright notice is preserved on all copies.
  1849. X *
  1850. X * There is no warranty or other guarantee of fitness for this software,
  1851. X * it is provided solely .  Bug reports or fixes may be sent
  1852. X * to the author, who may or may not act on them as he desires.
  1853. X *
  1854. X * You may not include this software in a program or other software product
  1855. X * without supplying the source, or without informing the end-user that the
  1856. X * source is available for no extra charge.
  1857. X *
  1858. X * If you modify this software, you should include a notice giving the
  1859. X * name of the person performing the modification, the date of modification,
  1860. X * and the reason for such modification.
  1861. X *
  1862. X * $Id: raytrace.h,v 3.0 89/10/27 02:06:03 craig Exp $
  1863. X *
  1864. X * $Log:    raytrace.h,v $
  1865. X * Revision 3.0  89/10/27  02:06:03  craig
  1866. X * Baseline for first official release.
  1867. X * 
  1868. X */
  1869. Xtypedef struct {
  1870. X    float x, y, size;    /* location and size */
  1871. X    Color ul, ur, ll, lr;    /* Color values of four corners */
  1872. X} pixel_square;
  1873. X
  1874. Xpixel_square *SquareStack;
  1875. Xdouble Minsquare;
  1876. X
  1877. X/*
  1878. X * "Dither matrices" used to encode the 'number' of a ray that samples a
  1879. X * particular portion of a pixel.  Hand-coding is ugly, but...
  1880. X */
  1881. Xint OneSample[1] =     {0};
  1882. Xint TwoSamples[4] =    {0, 2,
  1883. X             3, 1};
  1884. Xint ThreeSamples[9]=     {0, 2, 7,
  1885. X             6, 5, 1,
  1886. X             3, 8, 4};
  1887. Xint FourSamples[16] =    { 0,  8,  2, 10,
  1888. X             12,  4, 14,  6,
  1889. X              3, 11,  1,  9,
  1890. X             15,  7, 13,  5};
  1891. Xint FiveSamples[25] =    { 0,  8, 23, 17,  2,
  1892. X             19, 12,  4, 20, 15,
  1893. X              3, 21, 16,  9,  6,
  1894. X             14, 10, 24,  1, 13,
  1895. X             22,  7, 18, 11,  5};
  1896. END_OF_FILE
  1897. if test 1649 -ne `wc -c <'src/raytrace.h'`; then
  1898.     echo shar: \"'src/raytrace.h'\" unpacked with wrong size!
  1899. fi
  1900. # end of 'src/raytrace.h'
  1901. fi
  1902. if test -f 'src/texture.h' -a "${1}" != "-c" ; then 
  1903.   echo shar: Will not clobber existing file \"'src/texture.h'\"
  1904. else
  1905. echo shar: Extracting \"'src/texture.h'\" \(1474 characters\)
  1906. sed "s/^X//" >'src/texture.h' <<'END_OF_FILE'
  1907. X/*
  1908. X * texture.h
  1909. X *
  1910. X * Copyright (C) 1989, Craig E. Kolb
  1911. X *
  1912. X * This software may be freely copied, modified, and redistributed,
  1913. X * provided that this copyright notice is preserved on all copies.
  1914. X *
  1915. X * There is no warranty or other guarantee of fitness for this software,
  1916. X * it is provided solely .  Bug reports or fixes may be sent
  1917. X * to the author, who may or may not act on them as he desires.
  1918. X *
  1919. X * You may not include this software in a program or other software product
  1920. X * without supplying the source, or without informing the end-user that the
  1921. X * source is available for no extra charge.
  1922. X *
  1923. X * If you modify this software, you should include a notice giving the
  1924. X * name of the person performing the modification, the date of modification,
  1925. X * and the reason for such modification.
  1926. X *
  1927. X * $Id: texture.h,v 3.0 89/10/27 02:06:06 craig Exp $
  1928. X *
  1929. X * $Log:    texture.h,v $
  1930. X * Revision 3.0  89/10/27  02:06:06  craig
  1931. X * Baseline for first official release.
  1932. X * 
  1933. X */
  1934. X
  1935. X#define CHECKER        0    /* Checkerboard */
  1936. X#define BLOTCH        1    /* Color blotches */
  1937. X#define BUMP        2    /* Bump mapping */
  1938. X#define MARBLE        3    /* marble texture */
  1939. X#define FBM        4    /* fBm texture */
  1940. X#define FBMBUMP        5    /* fBm bump map */
  1941. X#define WOOD        6
  1942. X
  1943. XTexture *NewCheckText(), *NewBlotchText(), *NewBumpText(), *NewMarbleText();
  1944. XTexture *NewfBmText(), *NewfBmBumpText();
  1945. XTexture *NewWoodText();
  1946. X/*
  1947. X * Texturing routines.
  1948. X */
  1949. Xint    CheckerText(), BlotchText(), BumpText(), MarbleText(), fBmText();
  1950. Xint    fBmBumpText(), WoodText();
  1951. END_OF_FILE
  1952. if test 1474 -ne `wc -c <'src/texture.h'`; then
  1953.     echo shar: \"'src/texture.h'\" unpacked with wrong size!
  1954. fi
  1955. # end of 'src/texture.h'
  1956. fi
  1957. if test -f 'src/typedefs.h' -a "${1}" != "-c" ; then 
  1958.   echo shar: Will not clobber existing file \"'src/typedefs.h'\"
  1959. else
  1960. echo shar: Extracting \"'src/typedefs.h'\" \(1750 characters\)
  1961. sed "s/^X//" >'src/typedefs.h' <<'END_OF_FILE'
  1962. X/*
  1963. X * typedefs.h
  1964. X *
  1965. X * Copyright (C) 1989, Craig E. Kolb
  1966. X *
  1967. X * This software may be freely copied, modified, and redistributed,
  1968. X * provided that this copyright notice is preserved on all copies.
  1969. X *
  1970. X * There is no warranty or other guarantee of fitness for this software,
  1971. X * it is provided solely .  Bug reports or fixes may be sent
  1972. X * to the author, who may or may not act on them as he desires.
  1973. X *
  1974. X * You may not include this software in a program or other software product
  1975. X * without supplying the source, or without informing the end-user that the
  1976. X * source is available for no extra charge.
  1977. X *
  1978. X * If you modify this software, you should include a notice giving the
  1979. X * name of the person performing the modification, the date of modification,
  1980. X * and the reason for such modification.
  1981. X *
  1982. X * $Id: typedefs.h,v 3.0 89/10/27 02:06:07 craig Exp $
  1983. X *
  1984. X * $Log:    typedefs.h,v $
  1985. X * Revision 3.0  89/10/27  02:06:07  craig
  1986. X * Baseline for first official release.
  1987. X * 
  1988. X */
  1989. X#include "datatypes.h"
  1990. X#include "primobj.h"
  1991. X
  1992. X/*
  1993. X * Light definition.
  1994. X */
  1995. Xtypedef struct {
  1996. X    char type;        /* Light source type */
  1997. X    Vector pos;        /* Position / direction */
  1998. X    Color color;        /* Color (always normalized) */
  1999. X    double radius;        /* Radius (for extended sources) */
  2000. X    Primitive **cache;
  2001. X    TransInfo *trans;
  2002. X} Light;
  2003. X
  2004. X/*
  2005. X * Object node definition
  2006. X */
  2007. Xtypedef struct Object {
  2008. X    char *name;        /* Object name, if any. */
  2009. X    char type;        /* Type (grid, list, sphere, cone...) */
  2010. X    char *data;        /* Pointer to list/grid/primitive */
  2011. X    Trans *trans;        /* Transformation information */
  2012. X    double bounds[2][3];    /* Bounding box */
  2013. X#ifdef LINDA
  2014. X    unsigned long *counter;
  2015. X#else
  2016. X    unsigned long counter;        /* # of last grid checked against */
  2017. X#endif
  2018. X    struct Texture *texture;    /* Texture mapping info. */
  2019. X} Object;
  2020. END_OF_FILE
  2021. if test 1750 -ne `wc -c <'src/typedefs.h'`; then
  2022.     echo shar: \"'src/typedefs.h'\" unpacked with wrong size!
  2023. fi
  2024. # end of 'src/typedefs.h'
  2025. fi
  2026. if test -f 'src/version.c' -a "${1}" != "-c" ; then 
  2027.   echo shar: Will not clobber existing file \"'src/version.c'\"
  2028. else
  2029. echo shar: Extracting \"'src/version.c'\" \(1138 characters\)
  2030. sed "s/^X//" >'src/version.c' <<'END_OF_FILE'
  2031. X/*
  2032. X * version.c
  2033. X *
  2034. X * Copyright (C) 1989, Craig E. Kolb
  2035. X *
  2036. X * This software may be freely copied, modified, and redistributed,
  2037. X * provided that this copyright notice is preserved on all copies.
  2038. X *
  2039. X * There is no warranty or other guarantee of fitness for this software,
  2040. X * it is provided solely .  Bug reports or fixes may be sent
  2041. X * to the author, who may or may not act on them as he desires.
  2042. X *
  2043. X * You may not include this software in a program or other software product
  2044. X * without supplying the source, or without informing the end-user that the
  2045. X * source is available for no extra charge.
  2046. X *
  2047. X * If you modify this software, you should include a notice giving the
  2048. X * name of the person performing the modification, the date of modification,
  2049. X * and the reason for such modification.
  2050. X *
  2051. X * $Id: version.c,v 3.0 89/10/27 02:06:08 craig Exp $
  2052. X *
  2053. X * $Log:    version.c,v $
  2054. X * Revision 3.0  89/10/27  02:06:08  craig
  2055. X * Baseline for first official release.
  2056. X * 
  2057. X */
  2058. X#include <stdio.h>
  2059. X#include "patchlevel.h"
  2060. X
  2061. Xprint_version()
  2062. X{
  2063. X    extern char rcsid[];
  2064. X    extern FILE *fstats;
  2065. X
  2066. X    fprintf(fstats,"rayshade: %s\nPatch level %d\n",rcsid, PATCHLEVEL);
  2067. X}
  2068. END_OF_FILE
  2069. if test 1138 -ne `wc -c <'src/version.c'`; then
  2070.     echo shar: \"'src/version.c'\" unpacked with wrong size!
  2071. fi
  2072. # end of 'src/version.c'
  2073. fi
  2074. if test -f 'src/viewing.c' -a "${1}" != "-c" ; then 
  2075.   echo shar: Will not clobber existing file \"'src/viewing.c'\"
  2076. else
  2077. echo shar: Extracting \"'src/viewing.c'\" \(2211 characters\)
  2078. sed "s/^X//" >'src/viewing.c' <<'END_OF_FILE'
  2079. X/*
  2080. X * viewing.c
  2081. X *
  2082. X * Copyright (C) 1989, Craig E. Kolb
  2083. X *
  2084. X * This software may be freely copied, modified, and redistributed,
  2085. X * provided that this copyright notice is preserved on all copies.
  2086. X *
  2087. X * There is no warranty or other guarantee of fitness for this software,
  2088. X * it is provided solely .  Bug reports or fixes may be sent
  2089. X * to the author, who may or may not act on them as he desires.
  2090. X *
  2091. X * You may not include this software in a program or other software product
  2092. X * without supplying the source, or without informing the end-user that the
  2093. X * source is available for no extra charge.
  2094. X *
  2095. X * If you modify this software, you should include a notice giving the
  2096. X * name of the person performing the modification, the date of modification,
  2097. X * and the reason for such modification.
  2098. X *
  2099. X * $Id: viewing.c,v 3.0 89/10/27 02:06:08 craig Exp $
  2100. X *
  2101. X * $Log:    viewing.c,v $
  2102. X * Revision 3.0  89/10/27  02:06:08  craig
  2103. X * Baseline for first official release.
  2104. X * 
  2105. X */
  2106. X#include <math.h>
  2107. X#include <stdio.h>
  2108. X#include "constants.h"
  2109. X#include "typedefs.h"
  2110. X#include "funcdefs.h"
  2111. X
  2112. XVector lookp, eyep, up, firstray, scrnx, scrny;
  2113. Xdouble vfov, hfov, Separation;
  2114. Xint Xres = UNSET, Yres = UNSET, Stereo;
  2115. Xviewing()
  2116. X{
  2117. X    Vector gaze;
  2118. X    double dist, magnitude;
  2119. X
  2120. X    vecsub(lookp, eyep, &gaze);
  2121. X    firstray = gaze;
  2122. X
  2123. X    dist = normalize(&gaze);
  2124. X    (void)crossp(&scrnx, &gaze, &up);
  2125. X    (void)crossp(&scrny, &scrnx, &gaze);
  2126. X    dist *= 2.0;
  2127. X
  2128. X    /*
  2129. X     * Add stereo separation if desired.
  2130. X     */
  2131. X    if (Stereo) {
  2132. X        if (Stereo == LEFT)
  2133. X            magnitude = -.5 * Separation;
  2134. X        else
  2135. X            magnitude = .5 * Separation;
  2136. X        eyep.x += magnitude * scrnx.x;
  2137. X        eyep.y += magnitude * scrnx.y;
  2138. X        eyep.z += magnitude * scrnx.z;
  2139. X        vecsub(lookp, eyep, &firstray);
  2140. X        gaze = firstray;
  2141. X        dist = normalize(&gaze);
  2142. X        (void)crossp(&scrnx, &gaze, &up);
  2143. X        (void)crossp(&scrny, &scrnx, &gaze);
  2144. X    }
  2145. X
  2146. X    magnitude = dist * tan(deg2rad(0.5*hfov)) / Xres;
  2147. X    scrnx.x *= magnitude;
  2148. X    scrnx.y *= magnitude;
  2149. X    scrnx.z *= magnitude;
  2150. X    magnitude = dist * tan(deg2rad(0.5*vfov)) / Yres;
  2151. X    scrny.x *= magnitude;
  2152. X    scrny.y *= magnitude;
  2153. X    scrny.z *= magnitude;
  2154. X
  2155. X    firstray.x += 0.5*Yres*scrny.x - 0.5*Xres*scrnx.x;
  2156. X    firstray.y += 0.5*Yres*scrny.y - 0.5*Xres*scrnx.y;
  2157. X    firstray.z += 0.5*Yres*scrny.z - 0.5*Xres*scrnx.z;
  2158. X}
  2159. END_OF_FILE
  2160. if test 2211 -ne `wc -c <'src/viewing.c'`; then
  2161.     echo shar: \"'src/viewing.c'\" unpacked with wrong size!
  2162. fi
  2163. # end of 'src/viewing.c'
  2164. fi
  2165. echo shar: End of archive 1 \(of 8\).
  2166. cp /dev/null ark1isdone
  2167. MISSING=""
  2168. for I in 1 2 3 4 5 6 7 8 ; do
  2169.     if test ! -f ark${I}isdone ; then
  2170.     MISSING="${MISSING} ${I}"
  2171.     fi
  2172. done
  2173. if test "${MISSING}" = "" ; then
  2174.     echo You have unpacked all 8 archives.
  2175.     rm -f ark[1-9]isdone
  2176. else
  2177.     echo You still need to unpack the following archives:
  2178.     echo "        " ${MISSING}
  2179. fi
  2180. ##  End of shell archive.
  2181. exit 0
  2182.  
  2183.  
  2184.